home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCSmallEiffel / lib_se / call_infix_eq.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.9 KB  |  194 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CALL_INFIX_EQ
  17.    --   
  18.    --   Infix operator : "=".
  19.    --   
  20.  
  21. inherit CALL_INFIX_EQ_NEQ;
  22.    
  23. creation make
  24.    
  25. feature 
  26.    
  27.    operator: STRING is 
  28.       do
  29.      Result := us_eq;
  30.       end;
  31.    
  32.    is_static: BOOLEAN is
  33.       do
  34.      if target.is_void then
  35.         Result := is_static_eq_void(arg1);
  36.      elseif arg1.is_void then
  37.         Result := is_static_eq_void(target);
  38.      elseif target.is_static and then arg1.is_static then
  39.         Result := true;
  40.         if target.static_value = arg1.static_value then
  41.            static_value_mem := 1;
  42.         end;
  43.      end;
  44.       end;
  45.    
  46.    compile_to_c is
  47.       local
  48.      tt, at: TYPE;
  49.       do
  50.      tt := target.result_type.run_type;
  51.      at := arg1.result_type.run_type;
  52.      if tt.is_expanded then
  53.         if at.is_expanded then -- ------------- Expanded/Expanded :
  54.            if tt.is_user_expanded then
  55.           cmp_user_expanded(true,tt);
  56.            elseif tt.is_basic_eiffel_expanded then
  57.           cmp_basic_eiffel_expanded(true,at,tt);
  58.            elseif tt.is_bit then
  59.           cmp_bit(true,tt);
  60.            else -- NATIVE_ARRAY
  61.           cmp_basic_ref(true);
  62.            end;
  63.         else -- ------------------------------- Expanded/Reference :
  64.            c2c_exp_ref(target,tt,arg1,at);
  65.         end;
  66.      elseif at.is_expanded then -- ----------- Reference/Expanded :
  67.         c2c_exp_ref(arg1,at,target,tt);
  68.      else -- ---------------------------- Reference/Reference :
  69.         cmp_basic_ref(true);
  70.      end;
  71.       end;
  72.  
  73. feature {NONE}
  74.  
  75.    c2c_exp_ref(e: EXPRESSION; et: TYPE; r: EXPRESSION; rt: TYPE) is
  76.       do
  77.      if r.is_void then
  78.         cpp.put_string("((");
  79.         e.compile_to_c;
  80.         cpp.put_string("),0)");
  81.      else
  82.         cpp.put_string("((");
  83.         e.compile_to_c;
  84.         cpp.put_string("),(");
  85.         r.compile_to_c;
  86.         cpp.put_string("),0)");
  87.      end;
  88.       end;
  89.    
  90. feature {NONE}
  91.  
  92.    is_static_eq_void(e: EXPRESSION): BOOLEAN is
  93.       local
  94.      rt: TYPE;
  95.       do
  96.      if e.is_current then
  97.         Result := true;
  98.      elseif e.is_manifest_string then
  99.         Result := true;
  100.      elseif is_manifest_array(e) then
  101.         Result := true;
  102.      else
  103.         rt := e.result_type.run_type;
  104.         if rt.is_expanded then
  105.            if e.can_be_dropped then
  106.           Result := true;
  107.            end;
  108.         elseif e.is_static then
  109.            if e.static_value = 0 then
  110.           Result := true;
  111.           static_value_mem := 1;
  112.            end;
  113.         end;
  114.      end;
  115.       end;
  116.  
  117. feature 
  118.  
  119.    compile_to_jvm is
  120.       local
  121.      space, point1, point2: INTEGER;
  122.      rt: TYPE;
  123.      rc: RUN_CLASS;
  124.       do
  125.      if target.is_void then
  126.         jvm_void_cmp(arg1);
  127.      elseif arg1.is_void then
  128.         jvm_void_cmp(target);
  129.      else
  130.         rt := target.result_type.smallest_ancestor(arg1.result_type);
  131.         space := target.compile_to_jvm_into(rt);
  132.         space := arg1.compile_to_jvm_into(rt);
  133.         if rt.is_user_expanded then
  134.            rc := rt.run_class;
  135.            jvm_standard_is_equal_aux(rc,rc.writable_attributes);
  136.         else
  137.            point1 := rt.jvm_if_x_eq;
  138.            code_attribute.opcode_iconst_0;
  139.            point2 := code_attribute.opcode_goto;
  140.            code_attribute.resolve_u2_branch(point1);
  141.            code_attribute.opcode_iconst_1;
  142.            code_attribute.resolve_u2_branch(point2);
  143.         end;
  144.      end;
  145.       end;
  146.    
  147.    jvm_branch_if_false: INTEGER is
  148.       do
  149.      Result := jvm_standard_branch_if_false;
  150.       end;
  151.    
  152.    jvm_branch_if_true: INTEGER is
  153.       do
  154.      Result := jvm_standard_branch_if_true;
  155.       end;
  156.    
  157. feature {NONE}
  158.  
  159.    jvm_void_cmp(e: EXPRESSION) is
  160.       local
  161.      rt: TYPE;
  162.      point1, point2: INTEGER;
  163.      space: INTEGER;
  164.       do
  165.      rt := e.result_type.run_type;
  166.      if rt.is_expanded then
  167.         e.compile_to_jvm;
  168.         from
  169.            space := rt.jvm_stack_space;
  170.         until
  171.            space = 0
  172.         loop
  173.            code_attribute.opcode_pop;
  174.            space := space - 1;
  175.         end;
  176.         code_attribute.opcode_iconst_0;
  177.      else
  178.         e.compile_to_jvm;
  179.         point1 := code_attribute.opcode_ifnull;
  180.         code_attribute.opcode_iconst_0;
  181.         point2 := code_attribute.opcode_goto;
  182.         code_attribute.resolve_u2_branch(point1);
  183.         code_attribute.opcode_iconst_1;
  184.         code_attribute.resolve_u2_branch(point2);
  185.      end;
  186.       end;
  187.  
  188. invariant
  189.    
  190.    run_feature = Void;
  191.  
  192. end -- CALL_INFIX_EQ
  193.  
  194.